
use Data/Estimation_sample.dta, clear
	
	gen nexis_buildings  = ROOFME/PROOFME
		
		
	gen roofratio = ROOFME/ROOFTI
	gen roofratiobuildings = roofratio*nexis_buildings
		
	gen roofrelativeIV = (roofratio*nexis_buildings/[moduleprice])/1000

	
	
	
 
* 3 quarters is nine months 
local length = 3
	 
forval t = 0(1)`length' {
	gen event_after`t' =  SHCP_end ==`t' |  PFIT_starttime==`t' | PFIT_endtime==`t' | ///
	 SRES1_end ==`t' | SRES2_end==`t' | SRES_TFIT_endtime==`t' | FFIT_endtime==`t'
	 
	 
	 gen event_before`t' =  SHCP_end ==-`t'  | PFIT_starttime==-`t' | PFIT_endtime==-`t' | ///
	 SRES1_end ==-`t' | SRES2_end==-`t' | SRES_TFIT_endtime==-`t' | FFIT_endtime==-`t'
	
	gen event_after_new`t' = event_after`t'*cum
	gen event_before_new`t' = event_before`t'*cum
	
	gen event_after_high`t' = event_after`t'*roofrelativeIV
	gen event_before_high`t' = event_before`t'*roofrelativeIV
	
	label variable event_after`t' "+ `t'"
	label variable event_before`t' "- `t'"
	
	
	
	
	
	}
		
		
		
		
		egen countevent = rowtotal(event_before3 event_before2 event_before1 event_before0 event_after1 event_after2 event_after3 )
		
		
graph	bar event_before3 event_before2 event_before1 event_before0 event_after1 event_after2 event_after3, yscale(range(-0.05 0.4)) ylabel(0(0.1)0.4) yline(0)  ///
 bar(1, color(blue))  bar(2, color(blue))  bar(3, color(blue))  bar(4, color(gs0))  bar(5, color(red))  bar(6, color(red))  bar(7, color(red))  intensity (0) legend(off) ///
lintensity(*2) bargap(5) text(-0.025 50 "-3               -2               -1                0                1               2               3")
		
		
		
		
		
		tab countevent 
		
		label variable countevent "Events per observation"
		
		
		
		estpost tabulate countevent  
		
		esttab . using Analysis/Countevents.tex , cells("b pct(fmt(2))") noobs collabels("Observations" "Cumulative \%") nomtitle nonumber replace

		
		
		
	
	  
